import request from '@/utils/request'
import { strIsNotEmpty,generateUuid } from "@/views/youshuda/utils/youshuda";

// 根据模块名获取请求前缀
export function getPrefixUrl(busName) {
  return request({
    url: '/common/getPrefixUrl/' + busName,
    method: 'get'
  })
}

// 查询数据表单设计配置信息
export function getFormBuildConfig(formBuildKey) {
  return request({
    url: '/common/fromBuildConfig/' + formBuildKey,
    method: 'get'
  })
}

// 初始化字段信息
export function init(tabGenId,prefixUrl){
  let url = prefixUrl+'/init'
  if(strIsNotEmpty(tabGenId)){
    url='/common/basemode/init/'+tabGenId
  }
  return request({
    url:url,
    method:'get'
  })
}

// 查询数据列表
export function list(tabGenId,prefixUrl,query) {
  let url = prefixUrl+'/list'
  if(strIsNotEmpty(tabGenId)){
    url='/common/basemode/list/'+tabGenId
  }
  return request({
    url: url,
    method: 'get',
    params: query
  })
}

// 查询数据详细
export function getDetail(tabGenId,prefixUrl,id) {
  let url = prefixUrl+'/' + id
  if(strIsNotEmpty(tabGenId)){
    url='/common/basemode/'+tabGenId+'/' + id
  }
  return request({
    url: url,
    method: 'get'
  })
}

// 新增数据
export function add(tabGenId,prefixUrl,data) {
  let url = prefixUrl
  if(strIsNotEmpty(tabGenId)){
    url='/common/basemode/'+tabGenId
  }
  return request({
    url: url,
    method: 'post',
    data: data
  })
}

// 修改数据
export function update(tabGenId,prefixUrl,data) {
  let url = prefixUrl
  if(strIsNotEmpty(tabGenId)){
    url='/common/basemode/'+tabGenId
  }
  return request({
    url: url,
    method: 'put',
    data: data
  })
}

// 删除数据
export function del(tabGenId,prefixUrl,id) {
  let url = prefixUrl+'/' + id
  if(strIsNotEmpty(tabGenId)){
    url='/common/basemode/'+tabGenId+'/' + id
  }
  return request({
    url: url,
    method: 'delete'
  })
}

// 删除数据
export function exportDataTemplate(tabGenId,prefixUrl, params, filename, config) {
  let url = prefixUrl+'/' + id
  if(strIsNotEmpty(tabGenId)){
    url='/common/basemode/'+tabGenId+'/' + id
  }
  this.download(this.prefixUrl+'/importTemplate', {
    ...params
  }, `${this.componentDesc+'_模块'}.xlsx`)
}

// 查询菜单树
export function getMenus() {
  return request({
    url: "/getMenus",
    method: 'get'
  })
}

// 查询表信息
export function getDatabaseTableList(params) {
  return request({
    url: "tool/gen/db/table/list?pageNum="+params.pageNum+"&pageSize="+params.pageSize+"&queryAllTable=1&tableName="+params.tableName,
    method: 'get'
  })
}


// 保存menutree
export function saveMenuTree(data) {
  return request({
    url: '/saveMenusTree',
    method: 'post',
    data: data
  })
}

// 生成JSON串并保存
export function saveFormbuild(data) {
  return request({
    url: '/form/save',
    method: 'post',
    data: data
  })
}

// 调用优树搭树
export function dealMksApi(procTarget,reqData) {
  return request({
    url: '/MksAp/ProcRun/deal?reqTag='+generateUuid()+"&procTarget="+procTarget,
    method: 'post',
    data: reqData
  })
}

